#import "YHRefreshHeader.h"
#import "YHRefreshUtils.h"


@interface YHRefreshHeader ()
@property (nonatomic, strong) UIImageView *logoImgView;
@property (nonatomic, strong) UILabel *label;
@end


@implementation YHRefreshHeader
- (void)prepare {
    [super prepare];
    self.mj_h = 50;
    self.automaticallyChangeAlpha = YES;
    UILabel *label = [[UILabel alloc] init];
//    label.textColor = [UIColor colorWithRed:254 / 255.0 green:59 / 255.0 blue:125 / 255.0 alpha:1.0];
    label.font = [UIFont systemFontOfSize:12];
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
    self.label = label;
    UIImageView *logoImgV = [[UIImageView alloc] init];
    logoImgV.mj_size = CGSizeMake(18, 20);
    logoImgV.image = [YHRefreshUtils getImageFromBundle:@"ic_pull_refresh_normal"];
    [self addSubview:logoImgV];
    self.logoImgView = logoImgV;
}
- (void)placeSubviews {
    [super placeSubviews];
    self.label.bounds = CGRectMake(0, 0, [self.label mj_textWidth], 16);
    self.label.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5);
    self.logoImgView.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5);
    self.logoImgView.mj_x = self.label.mj_x - self.logoImgView.mj_w - 8;
}
- (void)setState:(MJRefreshState)state {
    MJRefreshCheckState;
//    self.label.textColor = [UIColor colorWithRed:254 / 255.0 green:59 / 255.0 blue:125 / 255.0 alpha:1.0];
    switch (state) {
        case MJRefreshStateIdle:
            self.label.text = @"下拉刷新";
            break;
        case MJRefreshStatePulling:
            self.label.text = @"松开刷新";
            break;
        case MJRefreshStateRefreshing:
            self.label.text = @"正在刷新";
            break;
        default:
            break;
    }
}
@end
